import { findAllWire, findWireById } from '@/apis/wireAPI'
import { PageModel, wireModel } from '@/types/model'
import { pageModel } from '@/util/pageModel'
import { ref } from 'vue'

export default () => {
  const wires = ref<PageModel<wireModel>>()
  const wire = ref<wireModel>()

  const all = async (args = {}) => {
    const { data } = await findAllWire(args)
    wires.value = pageModel<wireModel>(data, args)
  }

  async function find(id: number) {
    const { data } = await findWireById(id)
    wire.value = data
    return data
  }
  return { all, find, wire, wires }
}
